package com.qiu.injector;

import cn.dev33.satoken.stp.StpInterface;
import com.qiu.entity.UserRole;
import com.qiu.service.UserRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
 * sa-token 自定义权限验证
 *
 * @author Captain
 */
@Component
public class StpInterfaceImpl implements StpInterface {
    @Autowired
    private UserRoleService userRoleService;


    /**
     * 权限码集合
     */
    @Override
    public List<String> getPermissionList(Object loginId, String loginType) {
        return Collections.emptyList();
    }

    /**
     * 当前登录用户的角色标识集合
     */
    @Override
    public List<String> getRoleList(Object loginId, String loginType) {
        List<UserRole> userRoles = userRoleService.selectByUserId(Integer.valueOf(loginId.toString()));
        return userRoles.stream()
                .map(arg -> arg.getRoleId().toString())
                .collect(Collectors.toList());
    }

}